package com.heisen.system.controller;


import com.heisen.base.entity.Api;
import com.heisen.system.dto.UserRoleDto;
import com.heisen.system.service.IUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import javax.validation.Valid;

/**
 * <p>
 * 用户角色关联表 前端控制器
 * </p>
 *
 * @author sen
 * @since 2023-12-24
 */
@Controller
@RequestMapping("/user-role")
public class UserRoleController {

    @Autowired
    private IUserRoleService userRoleService;

    /**
     * 用户 角色 关联
     * @param userRoleDto
     * @return
     */
    @PostMapping("/save")
    public Api save(@Valid @RequestBody UserRoleDto userRoleDto){

        return Api.ok( userRoleService.addSysUserRole(userRoleDto));
    }


    /**
     * 修改 角色 关联
     * @param userRoleDto
     * @return
     */
    @PostMapping("/updateSysUserRole.json")
    @PreAuthorize("hasAnyAuthority('UserRole:update')")
    public Api updateSysUserRole(@Valid @RequestBody UserRoleDto userRoleDto){

        return Api.ok( userRoleService.updateSysUserRole(userRoleDto));
    }

}
